<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>斐波空心反</title>
</head>

<body>
    <script>
        //空心三角形
        for (var i = 1; i <= 9; i++) {
            for (var k = 1; k <= 9 - i; k++) {
                document.write('&ensp;&nbsp;')
            }
            for (var j = 1; j <= 2 * i - 1; j++) {
                if (j == 1 || j == 2 * i - 1 || i == 9) {
                    document.write('★');
                } else {
                    document.write('&ensp;&nbsp;')
                }

            }
            document.write('<br>')
        }

        //取反法求质数
        var num = prompt('请输入一个数字');
        //假设是 质数 
        var flag = true;// 标记
        for (var i = 2; i < num; i++) {
            if (num % i == 0) {
                flag = false;// 换标记
                console.log(num + '不是质数');
                break;
            }
        }
        if (flag) {
            console.log(num + '质数');
        }

        //斐波那契数列
        var a = 1;
        var b = 1;
        var c;
        var sum = 2;
        for (var i = 2; i < 38; i++) {
            c = a + b;
            a = b;
            b = c;
            sum += b
        }
        console.log('n 为38的值是' + b, 'sum=' + sum);

    </script>
</body>

</html>